/*
 * Copyright (C) 2010 CODEBISTRO LLC, Sunnyvale, California.
 * All rights reserved. Proprietary and Confidential.
 */

package org.codebistro.util;

/**
 * Split a first bite from the path
 */
public class PathBite {
	static final char DELIMITER = '/';

	String bite;
	String rest;

	public PathBite(String path) {
		if (path != null) {
			int index = path.indexOf(DELIMITER);
			if (index >= 0) {
				bite = path.substring(0, index);
				rest = path.substring(index + 1);
			} else {
				bite = path;
				rest = "";
			}

		}
	}

	public String get() {
		return bite;
	}

	public boolean isEmpty() {
		return Strings.isNullOrEmpty(bite);
	}

	public String getRest() {
		return rest;
	}

	public boolean hasRest() {
		return rest != null && rest.length() > 0;
	}

	public static String getSelector(final String pathInfo) {
		return new PathBite(Strings14.unprefix(pathInfo, "/")).get();
	}
}
